public class XMLTeamFormatter implements TeamFormatter{

    private static volatile XMLTeamFormatter singletonInstance = null;

    private XMLTeamFormatter(){

    }

    public static synchronized XMLTeamFormatter getSingletonInstance(){
        if(singletonInstance == null){
            singletonInstance = new XMLTeamFormatter();
        }
        return singletonInstance;
    }
    @Override
    public String formatTeam(Team team) {
        StringBuilder sb = new StringBuilder();
        sb.append("<Team ").append("teamId=\"" + team.getTeamId() + "\" ").
                append("teamName=\"" + team.getTeamName() + "\" ").
                append("department=\"" + team.getDepartment() + "\">" + "\n");
        sb.append("\t<Creator ");
        Student creator = team.getCreator();
        sb.append("id=\"" + creator.getId() + "\" ").
                append("name=\"" + creator.getName() + "\" ").
                append("phoneNo=\"" + creator.getPhoneNo() + "\" ").
                append("email=\"" + creator.getEmail() + "\" ").
                append("studentNo=\"" + creator.getStudentNo() + "\" ");
        if (creator.getGender()) {
            sb.append("gender=\"女\" ");
        } else {
            sb.append("gender=\"男\" ");
        }
        sb.append("grade=\"" + creator.getGrade() + "\" ")
                .append("department=\"" + creator.getDepartment() + "\"/>" + "\n");
        sb.append("\t<StudentList>" + "\n");
        for (Student student : team.getStudentList()) {
            sb.append("\t\t<Student ")
                    .append("id=\"" + student.getId() + "\" ")
                    .append("name=\"" + student.getName() + "\" ")
                    .append("phoneNo=\"" + student.getPhoneNo() + "\" ")
                    .append("email=\"" + student.getEmail() + "\" ")
                    .append("studentNo=\"" + student.getStudentNo() + "\" ");
            if (student.getGender()) {
                sb.append("gender=\"女\" ");
            } else {
                sb.append("gender=\"男\" ");
            }
            sb.append("grade=\"" + student.getGrade() + "\" ").
                    append("department=\"" + student.getDepartment() + "\"/>" + "\n");
        }
        sb.append("\t</StudentList>" + "\n");
        sb.append("\t<TeacherList>" + "\n");
        for (Teacher teacher : team.getTeacherList()) {
            sb.append("\t\t<Teacher ")
                    .append("id=\"" + teacher.getId() + "\" ")
                    .append("name=\"" + teacher.getName() + "\" ")
                    .append("phoneNo=\"" + teacher.getPhoneNo() + "\" ")
                    .append("email=\"" + teacher.getEmail() + "\" ")
                    .append("teacherNo=\"" + teacher.getTeacherNo() + "\" ")
                    .append("department=\"" + teacher.getDepartment() + "\"/>" + "\n");
        }
        sb.append("\t</TeacherList>" + "\n");
        sb.append("</Team>" + "\n");
        return sb.toString();
    }
}
